package com.vector.demo.controller;

import com.vector.demo.pojo.Class;
import com.vector.demo.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 班级处理控制层
 */
@Controller
public class ClassController {

    @Autowired
    private ClassService classService;

    /**
     * 查询 Class 信息
     * @param model
     * @return
     */
    @RequestMapping("/selectClassController")
    public String selectClassController(Model model){
        List<Class> list = classService.selectClass();
        model.addAttribute("list",list);
        model.addAttribute("msg","添加成功");
        System.out.println(list);
        return "login";
    }

    /**
     * 添加 Class 信息
     */
    @RequestMapping("/addClassController")
    public String addClassController(){
//        Class aclass = new Class();
//        aclass.setCla_id(4);
//        aclass.setCla_name("计科二班");
//        aclass.setCla_stu_num(52);
//        classService.addClass(aclass);
        return "login";
    }

    /**
     * 删除 Class 信息
     */
    @RequestMapping("/dropClassController")
    public String dropClassController(int cla_id){
        classService.dropClassById(cla_id);
        return "selectGrade";
    }

    /**
     * 预更新 Class 信息
     */
    @RequestMapping("/preModifyClassController")
    public String preModifyClassController(int cla_id){
        classService.preModifyClass(cla_id);
        return "selectGrade";
    }
    /**
     * 更新 Class 信息
     */
    @RequestMapping("/modifyClassController")
    public String modifyClassController(Class aclass){
        classService.modifyClass(aclass);
        return "selectGrade";
    }

}
